package cn.feng.mall.mybatis.controller;

import cn.feng.mall.mybatis.model.UmsAdmin;
import cn.feng.mall.mybatis.service.UmsAdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;




@RestController
@RequestMapping("/admin")
public class UmsAdminController {

    @Autowired
    private UmsAdminService umsAdminService;

    @RequestMapping("/index")
    public String index() {
        return "hello";
    }

    /**
     * 管理员登录
     * @param model
     * @param username
     * @param password
     * @return
     */
    @RequestMapping("/login")
    public String login(Model model, String username, String password) {
        ModelAndView mav = new ModelAndView();
        UmsAdmin umsAdmin = new UmsAdmin();
        umsAdmin.setUsername(username);
        umsAdmin.setPassword(password);

        UmsAdmin umsAdmin1 = this.umsAdminService.umsAdminLogin(umsAdmin);
        if(ObjectUtils.isEmpty(umsAdmin1)) {
            mav.setStatus(HttpStatus.OK);
            mav.addObject("msg", "该用户不存在");
            return mav.toString();
        } else {
            mav.addObject("admin", umsAdmin1);
        }

        return mav.toString();
    }




}
